home *** CD-ROM | disk | FTP | other *** search
- Path: newsroom.hitc.com!usenet
- From: psand@eos.hitc.com (G. Patrick Sand)
- Newsgroups: comp.lang.c++
- Subject: Re: simple design question
- Date: 2 Feb 1996 16:34:42 GMT
- Organization: Hughes Aircraft (EOSDIS)
- Message-ID: <4etef2$3sc@newsroom.hitc.com>
- References: <DM4u8I.G1H@emr1.emr.ca>
- NNTP-Posting-Host: 155.157.118.56
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- In article <DM4u8I.G1H@emr1.emr.ca>, jagrant@emr1.emr.ca says...
- >
- >This is a design question, not a syntax question, so forgive the pseudo-
- >code.
- >
- >I'm trying to design/write a class for complex file I/O (I'll state it
- >in simple terms here).
- >
- >I want to use it like this:
- > object.Open("xxx")
- > for(...){
- > object.Read(stuff);
- > }
- > object.Close();
- >
- >But I want to also have a single function that will Open/Read/Close in a
- >single operation:
- > object.GetData("xxx",stuff);
- >
-
- Okay, the first question is this:
-
- 1. Do you want to reuse the open/close/read semantics in other classes?
-
- If so, make it a separate class and use inheritance to add it to classes
- where you wish to do complex I/O. If not, just make them methods in the
- desired class. I recommend that if you have 2 or more classes which will
- do this I/O create the I/O operations as a separate class and
- inherit--this is one of the maintenance blessing C++ and OOA/D confers on
- you...if you use it...
-
- The second question is this:
-
- 2. Why not use the iostreams/fstreams stuff? It does deal with
- clashes-like calling Open() then GetData()...although you will need to do
- some checking... This can be put into a separate class or built into the
- methods and save you some hassles...iostreams is very powerful, and a bit
- daunting at first, but as I'm learning it I am starting to prefer it over
- the printf/scanf functions I mastered in C...
-
- You might also want to have a separate class for the I/O and include
- state variables (i.e., attributes in OOD-speak) to indicate if you have a
- file, have it open, or have closed it....It looks like a string (or char
- pointer) for the filename and an int for SELECTED/OPENED/CLOSED/NONE...
-
- Might as well experiment with this stuff now, it's cheap (just time and
- electricity on your computer) and will benefit you greatly as you dig
- deeper into C++....
-
- BTW, I'm going to finally break down and buy and book on iostreams; I've
- reached the point where my needs exceed the usual discussions in the C++
- books...
-
- Hope this helps...
- --
- G. Patrick Sand
- psand@eos.hitc.com
- PatSand@aol.com
- (301) 925-0791
- "Travel Light But Right..."
- Microsoft Network is prohibited from redistributing
- this work in any form, in whole or in part. License
- to distribute this individual post is available to Microsoft
- for $999. Posting without permission constitutes an
- agreement to these terms...gps
-
-